<template>
	<view>
		<view class="pay-con">
			<view class="pay-item">
				<view>空压机</view>
				<view>郑州航海东路喷油螺杆压缩机</view>
			</view>
			<u-line color="#ececec"></u-line>
			<view class="pay-item">
				<view>物料类型</view>
				<view>{{payInfo.goodsName}}</view>
			</view>
			<u-line color="#ececec"></u-line>
			<view class="pay-item">
				<view>预计使用费用</view>
				<view>￥{{payInfo.totalPrice}}</view>
			</view>
			<u-line color="#ececec"></u-line>
			<view class="pay-item">
				<view>预选时长</view>
				<view>{{payInfo.time}}分钟</view>
			</view>
			<u-line color="#ececec"></u-line>
			<view class="pay-item">
				<view>货物载重</view>
				<view>{{payInfo.goodsWeight}}吨</view>
			</view>
			<u-line color="#ececec"></u-line>
			<view class="pay-item">
				<view>车牌号</view>
				<view>{{payInfo.carNo}}</view>
			</view>
		</view>
		<view class="pay-but" @click="goPay">
			<u-button type="primary" text="立即支付" customStyle="height: 90rpx;"></u-button>
		</view>
	</view>
</template>

<script>
	import {
		postCartAdd
	} from "@/api"
	export default {
		data() {
			return {
				payInfo: {}
			}
		},
		onLoad(option) {
			this.payInfo = JSON.parse(decodeURIComponent(option.item));
			console.log(this.payInfo);
		},
		methods: {
			async goPay() {
				uni.showLoading({
					mask: true,
					title: '支付中...'
				})
				try {
					const res = await postCartAdd({
						deviceNo: this.payInfo.deviceNo,
						deliveryName: this.payInfo.goodsName,
						handsel: this.payInfo.goodsWeight,
						totalNum: this.payInfo.time,
						// #ifdef MP-ALIPAY
						payType: "A02",
						// #endif
						// #ifdef MP-WEIXIN
						payType: "W06",
						// #endif
						realName: this.payInfo.carNo,
					})
					uni.hideLoading()
					// #ifdef MP-WEIXIN
					const payinfo = JSON.parse(res.data.payinfo)
					console.log(payinfo);
					uni.requestPayment({
						provider: "wxpay",
						nonceStr: payinfo.nonceStr,
						package: payinfo.package,
						timeStamp: payinfo.timeStamp,
						paySign: payinfo.paySign,
						signType: payinfo.signType,
						success(res) {
							console.log(55, res);
							uni.redirectTo({
								url: '/pages/order/order'
							})
						},
						fail(err) {
							console.log(66, err);
						}

					})
					// wx.openEmbeddedMiniProgram({
					// 	appId: 'wxe48aedff31caaf2d',
					// 	path: "pages/index/index",
					// 	extraData: res.data.payInfo,
					// 	success(resa) {
					// 		console.log("成功回调返回的res：" + JSON.stringify(resa))
					// 	},
					// 	fail(resa) {
					// 		console.log("失败回调返回的res：" + JSON.stringify(resa))
					// 	},
					// })
					// #endif
					// #ifdef MP-ALIPAY

					if (res.data) {
						console.log(234, res);
						uni.requestPayment({
							provider: "alipay",
							tradeNO: res.data.payinfo,
							success(resa) {
								console.log(567, resa);
								if (resa.resultCode == 9000) {
									uni.redirectTo({
										url: '/pages/order/order'
									})
								}

							},
							fail(err) {
								console.log(789, err);
							}

						})
					}


					// my.navigateToMiniProgram({
					// 	appId: '2021004162658199',
					// 	path: "pages/index/index",
					// 	extraData: res.data.payInfo,
					// 	success(resa) {
					// 		console.log("成功回调返回的res：" + JSON.stringify(resa))
					// 	},
					// 	fail(erra) {
					// 		console.log("失败回调返回的res：" + JSON.stringify(erra))
					// 	},
					// })
					// #endif
				} catch (error) {
					console.log(343, error);
					uni.hideLoading()
				}



			},
		}
	}
</script>

<style lang="scss" scoped>
	.pay-con {
		width: 100vw;
		background: #FFFFFF;
	}

	.pay-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		color: #333;
		font-size: 31rpx;
		height: 100rpx;
		width: 100vw;
		padding: 0 31rpx;
	}

	.pay-but {
		width: 688rpx;
		margin: 0 auto;
		margin-top: 100rpx;

		/deep/ .u-button__text {
			font-weight: 600 !important;
			font-size: 32rpx !important;
			letter-spacing: 5rpx !important;

		}
	}
</style>